package zhongbo.java.air.auth.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import zhongbo.java.air.auth.handler.AuthInterceptor;

/**
 * 说明：
 * 拦截器配置
 *
 * @author 钟波dellNotebook
 * @since 2025年03月30日 星期日 13:32:13
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(authInterceptor);
        interceptorRegistration
                // 放行 swagger-ui 资源
                .excludePathPatterns("/doc.html")
                .excludePathPatterns("/swagger-resources")
                .excludePathPatterns("/v2/api-docs")
                .excludePathPatterns("/webjars/**")
                // 放行 认证接口
                .excludePathPatterns("/auth/register")
                .excludePathPatterns("/auth/login")
                // 拦截剩余所有
                .addPathPatterns("/**");
    }
}
